<%@ page contentType="text/html; charset=UTF-8"%>

<%@ include file="../../common.jsp"%>
<%@ taglib uri="/page.util.gs.hitrust.com/taglibs/page" prefix="page"%>

<html>
<head>
<title>批量导入产品替换信息</title>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<LINK href="<%=root%>/css/caigouxitong.css" type=text/css rel=stylesheet>
<SCRIPT language="JavaScript" src="<%=root%>/js/calendar.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=root%>/js/common.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=root%>/js/string.js"></SCRIPT>
<%
	ResultProcess rst = (ResultProcess) session
			.getAttribute("productTemporaryMaintainExcel");
	ArrayList tList = new ArrayList();
	  List hourList=new ArrayList();
	    String hour="";
	    String minute="";
	    for(int i=0;i<=23;i++){
	    	hour=i+"";
	    	if(hour.length()==1){
	    		hour="0"+hour;
	    	}
	    	hourList.add(hour);
	    }
	    List minuteList=new ArrayList();
	    for(int j=0;j<=59;j++){
	    	minute=j+"";
	    	if(minute.length()==1){
	    		minute="0"+minute;
	    	}
	    	minuteList.add(minute);
	    }  
%>
<script type="text/javascript">
    function SelectAllCheckBox() {
        var des =document.getElementsByName('sel_manufacture');
        for(var i=0;i<des.length;i++) {
           if(des[i].checked=document.getElementById('ckbox').checked){
               des[i].checked=true;
           } else { 
               des[i].checked=false;
           }
        }
    }
</script>


</head>
<body BGCOLOR="#f2f2f2" text="#000000" leftmargin="0" topmargin="0"
	marginwidth="0" marginheight="0">
<form name="manufactureform" method="get"
	action="<%=response.encodeURL(request.getContextPath()
					+ "/A190017.do")%>">
<table width="98%" border="0" cellspacing="0" cellpadding="0"
	align="center">
	<tr>
		<td height="20">
		<table width="100%" border="0" cellspacing="0" cellpadding="1">
			<tr height="20">
				<td height="20" width="1" class="mtxt_black">&nbsp;</td>
				<td height="30" width="758" class="mtxt_black">批量导入产品替换信息确认</td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td class="bg_line" height="2"></td>
	</tr>
</table>
<br>
	<input name="type"
			type="hidden"
			value="<%=request.getParameter("type") == null ? "" : request
						.getParameter("type")%>">
<%
	if (rst != null) {
		int totalRecords = 0;
		int defaultPageSize = Integer
				.parseInt(GSBaseConstants.importPageSize);
		totalRecords = rst.getRecordsSize();
%> <page:pager total='<%=totalRecords%>'
	defaultPageSize='<%=defaultPageSize%>'>
	<%
		tList = rst.getDisplayRecords(index.intValue(),
						pageSize.intValue());
	%>
</page:pager> <%
 	}
 %>
</form>
<%
	if (rst != null && tList.size() > 0) {
%>
<center>
<table width="98%" border="0" cellspacing="0" cellpadding="0"
	align="center">
	<tr>
		<td>
		<form name='pager' method="post"><input name="choice"
			type="hidden"
			value="<%=request.getParameter("choice") == null ? "" : request
						.getParameter("choice")%>">
		<table class=bg_table id=tableId cellspacing=1 cellpadding=2
			width=100% align=center border=0>
			<tbody>
				<tr class="bg_column" height=20>

					<td class=top align="center">
					<div class="txt_content" align="center"><input
						type="checkbox" name="ckbox" onClick="SelectAllCheckBox()"></div>
					</td>
					<td class=top align="center" nowrap="nowrap">
					<div class="txt_content" align="center">序号</div>
					</td>

					<td class=top align="center" nowrap="nowrap">
					<div align="center" class="txt_content">替换集中编码</div>
					</td>

					<td class=top align="center" nowrap="nowrap">
					<div align="center" class="txt_content">替换产品名称</div>
					</td>

					<td class=top align="center" nowrap="nowrap">
					<div align="center" class="txt_content">替换产品单价</div>
					</td>
					
					<td class=top align="center" nowrap="nowrap">
					<div align="center" class="txt_content">被替换集中编码</div>
					</td>

					<td class=top align="center" nowrap="nowrap">
					<div align="center" class="txt_content">被替换产品名称</div>
					</td>

					<td class=top align="center" nowrap="nowrap">
					<div align="center" class="txt_content">被替换产品单价</div>
					</td>
					
					<td class=top align="center" nowrap="nowrap">
					<div align="center" class="txt_content">启用日期</div>
					</td>
					
				</tr>
				<%
					for (int i = 0; i < tList.size(); i++) {
							GSProductTemporaryMaintainView mv = (GSProductTemporaryMaintainView) tList
									.get(i);
							String tTempStr = "";
							if (i % 2 == 0) {
								tTempStr = "class=\"bg_row_odd\"";
							} else {
								tTempStr = "class=\"bg_row_even\"";
							}
				%>
				<tr <%=tTempStr%> height=20>
					<td class=top align="center"><input type=checkbox
						name="sel_manufacture" value="<%=mv.getGs_recorder_id()%>">
					<input type="hidden" name="gs_recorder_id"
						value="<%=mv.getGs_recorder_id()%>"></td>
					<td class=top align="center">
					<div align="center" class="txt_content"><%=i + 1%> <input
						type="hidden" name="gs_id" value="<%=mv.getGs_id()%>"></div>
					</td>

					<td class=top align="center">
					<div align="center" class="txt_content"><%=mv.getGs_concentricity_code()%>
					<input type="hidden" name="gs_concentricity_code"
						value="<%=mv.getGs_concentricity_code()%> "></div>
					</td>
					<td class=top align="center">
					<div align="center" class="txt_content"><%=mv.getGs_product_name()%>
					<input type="hidden" name="gs_product_name"
						value="<%=mv.getGs_product_name()%>"></div>
					</td>

					<td class=top align="center">
					<div align="center" class="txt_content"><%=mv.getGs_unit_price()%>
					<input type="hidden" name="gs_unit_price" value="<%=mv.getGs_unit_price()%>">
					</div>
					</td>
					
					<td class=top align="center">
					<div align="center" class="txt_content"><%=mv.getGs_temporary_concentricity_code()%>
					<input type="hidden" name="gs_temporary_concentricity_code"
						value="<%=mv.getGs_temporary_concentricity_code()%> "></div>
					</td>
					<td class=top align="center">
					<div align="center" class="txt_content"><%=mv.getGs_temporary_product_name()%>
					<input type="hidden" name="gs_temporary_product_name"
						value="<%=mv.getGs_temporary_product_name()%>"></div>
					</td>

					<td class=top align="center">
					<div align="center" class="txt_content"><%=mv.getGs_temporary_unit_price()%>
					<input type="hidden" name="gs_temporary_unit_price" value="<%=mv.getGs_temporary_unit_price()%>">
					</div>
					</td>

					<td class=top align="center">
					<div align="center" class="txt_content">
					<input type="text" name="gs_enabled_time" size="20" readonly onfocus='setday(this)'
					value="<%=mv.getGs_enabled_time()%>">
					  		<select id='hour' name='hour' >
						   		<%for(int k=0;k<hourList.size();k++){
						   			String hourStr=(String)hourList.get(k);
						   			%>
						   			<%if(mv.getGs_hour().equals(hourStr)) {%>
						   				<option value='<%=hourStr %>' selected><%=hourStr %></option>
						   			<%}else{ %>
						   				<option value='<%=hourStr %>' ><%=hourStr %></option>
						   		<%} }%>
                            	</select>
                            	时
                            	<select id='minute' name='minute' >
                            		 <%for(int m=0;m<minuteList.size();m++){
						   			String minuteStr=(String)minuteList.get(m);
						   			%>
						   			<%if(mv.getGs_minute().equals(minuteStr)) {%>
						   				<option value='<%=minuteStr %>' selected><%=minuteStr %></option>
						   			<%}else{ %>
						   				<option value='<%=minuteStr %>' ><%=minuteStr %></option>
						   		<%} }%>                    
                            	</select>
                            	分
					</div>
					</td>
				</tr>
				<%
					}
				%>
				<tr class="bg_column" height="20">

					<td width="960" height="16" colspan="18" align="right"><!--导航条-->
					<page:navigator type='text' queryForm="manufactureform" /></td>

				</tr>
			</tbody>
		</table>
		</form>
		</td>
	</tr>
	<tr>
		<td align="center" class="bg_row_odd"><input type="button"
			class="kuang" width="58" height="24" value="选择确认"
			onclick="writedb();" />&nbsp; <input type="button" class="kuang"
			width="58" height="24" value="移除产品" onclick="romove();" />&nbsp; <input
			type="button" class="kuang" width="58" height="24" value="重新导入"
			onclick="again();" />&nbsp; <input type="button" class="kuang"
			width="58" height="24" value="返回" onclick="again();" /></td>
	</tr>
</table>
</center>
<%
	} else {
%>
<br>
<div align="center" class="txt_content"><a
	href="<%=response.encodeURL(request.getContextPath()
						+ "/A190015.do")%>">无产品信息</a>
</div>
<%
	}
%>
<script>
    function romove() {
        var checkboxvalue = document.getElementsByName("sel_manufacture");
        var selectnum = 0;
        for(i=0;i<checkboxvalue.length;i++){
            if(checkboxvalue[i].checked){
             selectnum++;
            }
        }
        if(selectnum ==0) {
            alert("请至少选择一项产品");
            return false;
        }
        if(confirm("是否确定移除所选产品信息？")){
            var rootURL = "<%=response.encodeURL(request.getContextPath()
					+ "/A190018.do")%>";
            document.pager.action = encodeURI(rootURL);
            document.pager.submit();
        }
    }
    
    function writedb() {
        var checkboxvalue = document.getElementsByName("sel_manufacture");
        var enabledtime=document.getElementsByName("gs_enabled_time");
        var hour=document.getElementsByName("hour");
        var minute=document.getElementsByName("minute");
      
        var selectnum = 0;
        for(i=0;i<checkboxvalue.length;i++){
            if(checkboxvalue[i].checked){
                selectnum++;
            }
        }
        if(selectnum ==0) {
            alert("请至少选择一项产品");
            return false;
        }
        if(selectnum>0){
         	var patm = /^[^'"<>&]*$/;
            for(i=0;i<checkboxvalue.length;i++){
                if(checkboxvalue[i].checked){        
                    if(Trim(enabledtime[i].value)==''){
                        alert("请输入启用日期");
                        enabledtime[i].focus();
                        return false;
                    }
                    var time=Trim(enabledtime[i].value);
                    var timeStr = time.substring(0,4)+time.substring(5,7)+time.substring(8,10);
                     var hourStr=hour[i][hour[i].selectedIndex].innerText;
                     var minuteStr=minute[i][minute[i].selectedIndex].innerText;
             		if(parseInt(hourStr)==0){
           				hourStr=hourStr.substring(1,hourStr.length);
           			}
           			if(parseInt(minuteStr)==0){
           				minuteStr=minuteStr.substring(1,minuteStr.length);
           			}
                          
                    if(parseInt(timeStr)<<%=Long.parseLong(DateUtil.getCurrentDate("yyyyMMdd"))%>){
                    	 alert("启用日期不能比当前日期早");
                         enabledtime[i].focus();
                         return false;
                    }else if(parseInt(timeStr)==<%=Long.parseLong(DateUtil.getCurrentDate("yyyyMMdd"))%>&&
                    		parseInt(hourStr)<<%=Long.parseLong(DateUtil.getCurrentDate("HH"))%>){
                  		 alert("启用日期为当天时,启用时间不能晚于当前时间");
                         hour[i].focus();
                        return false; 
                   }else if(parseInt(timeStr)==<%=Long.parseLong(DateUtil.getCurrentDate("yyyyMMdd"))%>&&
                     		parseInt(hourStr)==<%=Long.parseLong(DateUtil.getCurrentDate("HH"))%>&&
                    		parseInt(minuteStr)<=<%=Long.parseLong(DateUtil.getCurrentDate("mm"))%>
                    		){
                 		alert("启用日期为当天时,启用时间必须大于当前时间");
                 		minute[i].focus();
                        return false; 
                   	  }else{
                    	enabledtime[i].value=enabledtime[i].value+' '+hour[i][hour[i].selectedIndex].innerText+':'
                    	 +minute[i][minute[i].selectedIndex].innerText+':00';
                    }
                }
            }
           
            if(confirm("是否确定写入所选产品替换信息？")){
                var rootURL = "<%=response.encodeURL(request.getContextPath()
					+ "/A190019.do")%>";
                document.pager.action = encodeURI(rootURL);
                document.pager.submit();
            }
        }
    }

    function again(){
        document.location.href="<%=response.encodeURL(request.getContextPath()
					+ "/A190015.do")%>";
    }
   
 </script>
</body>
</html>